package com.yang.action;

import com.yang.entity.Category;
import com.yang.service.CategoryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;

@WebServlet("/updateCategory")
public class CategoryUpdateAction extends HttpServlet {
    CategoryService categoryService = new CategoryService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Category category = new Category();
        String id = req.getParameter("id");
        category.setId(Integer.parseInt(id));
        String name = req.getParameter("name");
        category.setName(name);
        String parentid = req.getParameter("parentid");
        category.setParentid(Integer.parseInt(parentid));
        int num = categoryService.updateCategoryById(category);
        resp.setContentType("text/text;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.print(num);
        out.flush();
        out.close();
    }
}

